package com.coocaa.ops.admin.base.convert;

import com.coocaa.ops.admin.base.language.CommonLanguageProperties;
import com.coocaa.ops.common.core.base.constant.CornerPositionConstants;
import com.coocaa.ops.common.core.biz.cornericon.entity.GlobalCornerIconEntity;
import com.coocaa.ops.common.tool.base.InstanceUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @author bijiahao
 * @description
 * @date 2020/6/16 18:29
 */
@Component
public class CornerPositionConverter {
    private static CommonLanguageProperties commonLanguageProperties;

    /**
     * 获取所有角标ID-顺时针
     *
     * @param cornerIconEntityList
     * @return
     * @see CornerPositionConstants
     */
    public static List<Integer> getCornerIconIdList(List<GlobalCornerIconEntity> cornerIconEntityList) {
        List<Integer> cornerIconIdList = InstanceUtil.newArrayList(4);
        if (CollectionUtils.isNotEmpty(cornerIconEntityList)) {
            //左上角
            cornerIconIdList.add(getCornerIconId(cornerIconEntityList, CornerPositionConstants.LEFT_TOP));
            //右上角
            cornerIconIdList.add(getCornerIconId(cornerIconEntityList, CornerPositionConstants.RIGHT_TOP));
            //右下角
            cornerIconIdList.add(getCornerIconId(cornerIconEntityList, CornerPositionConstants.RIGHT_BOTTOM));
            //左下角
            cornerIconIdList.add(getCornerIconId(cornerIconEntityList, CornerPositionConstants.LEFT_BOTTOM));
        }
        return cornerIconIdList;
    }

    /**
     * 获取角标ID
     *
     * @param cornerIconEntityList
     * @param position
     * @return
     */
    private static Integer getCornerIconId(List<GlobalCornerIconEntity> cornerIconEntityList, Integer position) {
        for (GlobalCornerIconEntity cornerIconEntity : cornerIconEntityList) {
            if (null != cornerIconEntity && position.equals(cornerIconEntity.getPosition())) {
                Assert.notNull(cornerIconEntity.getId(), "CornerIconId" + commonLanguageProperties.getNotNull());
                return cornerIconEntity.getId();
            }
        }
        return 0;
    }

    @Autowired
    public void setCommonLanguageProperties(CommonLanguageProperties commonLanguageProperties) {
        CornerPositionConverter.commonLanguageProperties = commonLanguageProperties;
    }

}
